package org.wangblue;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

/**
 * @Description: 初始化ES, 初次连接ES
 * @Author: WangBlue
 * @Create: 2024-10-22 15:04
 * @Version: 1.0
 **/

public class InitElasticSearch {
    public static void main(String[] args) {

        RestHighLevelClient client = null;
        try {
            client = new RestHighLevelClient(
                    RestClient.builder(
                            new HttpHost("localhost", 9200, "http")
                    )
            );

            System.out.println(client);
        } catch (Exception e) {
            System.out.println("Error: " + e.getMessage());
        }finally {
            if (client!= null) {
                try {
                    client.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

    }
}
